## Explanation of Sound Driver Functions

INDEX Explanation of Sound Driver Functions

       (1)   Initialization of Sound Driver
       (2)   Setting Operation Mode of Sound Driver
       (3)   Main Loop of Sound Driver
       (4)   Setting of Sound DMA Each Time
       (5)   Stopping Sound DMA
       (6)   Restarting Sound DMA
       (7)   Stopping Production of All Direct Sounds
       (8)   Calculating Musical Interval with MIDI Key

#### (1) Initialization of Sound Driver

void SoundDriverInit(SoundArea *sa);

Initializes the sound driver. When starting up the game call only once. Also you need to set aside the work area, sa, in advance. Additionally, even if you have prepared a separate work area you cannot execute this driver multiple times.
Return to Top

#### (2) Setting Operation Mode of Sound Driver

void SoundDriverMode(u32 mode);

Sets operation mode of sound driver. The following values are used for the argument, mode. The constants represented by SOUND_MODE_xxxx_xxxx below are defined in AgbSound.h.

     -Direct Sound Reverb (Default Value 0)
         mode = SOUND_MODE_REVERB_SET + (Reverb Value 0-127);

     -Number of Simultaneously-Produced Direct Sounds (Default Value 8)
         mode = (Simultaneous Sounds 1-12) << SOUND_MODE_MAXCHN_SHIFT;

     -Direct Sound Master Volume (Default Value 15)
         mode = (Volume 1-15) << SOUND_MODE_MASVOL_SHIFT;

     -Direct Sound Playback Frequency (Default Value 13379Hz)
         mode = SOUND_MODE_FREQ_?????;
                (12 types of values defined in AgbSound.h)

     -Number of Bits for Final Output D/A Conversion (Default Value 8 bits)
         mode = SOUND_MODE_DA_BIT_?;
                (?= value of 9-6)

     (The preceding values can also be set at the same time using OR.)

Return to Top

#### (3) Main Loop of Sound Driver

void SoundDriverMain(void);

Main loop of the sound driver. Call every 1/60 of a second. The flow of the processing is: immediately following a V-Blank interrupt call SoundDriverVSync(), carry out processing for BG and OBJ, and then call this routine.
Return to Top

#### (4) Setting of Sound DMA Each Time

void SoundDriverVSync(void);

This is a function that sets the DMA being used with the sound every 1/60 of a second. The timing is extremely critical so be sure and call it immediately after each V-Blank interrupt every 1/60 of a second.
Return to Top

#### (5) Stopping Sound DMA

void SoundDriverVSyncOff(void);

There may be a situation in which you stop the V-Blank interrupt because of the main program. If you are not able to call SoundDriverVSync() every 1/60 of a second, the sound DMA must be stopped using this function. If this is not done, even if you exceed the limit of the transmit buffer the DMA will not stop and noise will result. Additionally, if you use DMA1, DMA2, or TIMER0 for some other purpose when stopping sound DMA, it becomes impossible to restart this driver and you will have to reinitialize using SoundDriverInit().
Return to Top

#### (6) Restarting Sound DMA

void SoundDriverVSyncOn(void);

This function restarts the sound DMA stopped with the above, SoundDriverVSyncOff(). After calling this function, make sure that within 1/60 of a second the V-Blank interrupt occurs and SoundDriverVSync() is called.
Return to Top

#### (7) Stopping Production of All Direct Sounds

void SoundChannelClear(void);

Clears all virtual channels of direct sound and stops sounds.
Return to Top

#### (8) Calculating Musical Interval with MIDI Key

u32 MidiKey2Freq(WaveData *wa, u8 mk, u8 fp);

When producing waveform data, wa, using the interval (MIDI KEY) mk and the fine control value, fp, the value to be substituted into ( (SoundArea)sa ).vchn[x].fr is calculated.
Return to Top

[ | Back | Programmer's Manual Table of Contents | Using AGB Direct Sound Driver Table of Contents | Next | ]